import request from '@/utils/request'

// 创建作业
export function createHomework(data) {
  return request({
    url: '/api/homework',
    method: 'post',
    data
  })
}

// 获取作业详情
export function getHomework(id) {
  return request({
    url: `/api/homework/${id}`,
    method: 'get'
  })
}

// 获取教师发布的作业列表
export function getTeacherHomeworks(teacherId) {
  return request({
    url: `/api/homework/teacher/${teacherId}`,
    method: 'get'
  })
}

// 获取学生的作业列表
export function getStudentHomeworks(studentId) {
  return request({
    url: `/api/homework/student/${studentId}`,
    method: 'get'
  })
}

// 更新作业状态
export function updateHomeworkStatus(id, status) {
  return request({
    url: `/api/homework/${id}/status`,
    method: 'put',
    params: { status }
  })
}

// 添加作业题目
export function addQuestion(question) {
  return request({
    url: '/api/homework/question',
    method: 'post',
    data: question
  })
}

// 更新作业题目
export function updateQuestion(question) {
  return request({
    url: '/api/homework/question',
    method: 'put',
    data: question
  })
}

// 删除作业题目
export function deleteQuestion(questionId) {
  return request({
    url: `/api/homework/question/${questionId}`,
    method: 'delete'
  })
}

// 获取作业题目列表
export function getQuestions(homeworkId) {
  return request({
    url: `/api/homework/${homeworkId}/questions`,
    method: 'get'
  })
}

// 提交作业答案
export function submitAnswer(answer) {
  return request({
    url: '/api/homework/answer',
    method: 'post',
    data: answer
  })
}

// 更新作业答案
export function updateAnswer(answerId, answerContent) {
  return request({
    url: `/api/homework/answer/${answerId}`,
    method: 'put',
    params: { answerContent }
  })
}

// 获取学生的作业答案
export function getStudentAnswers(homeworkId, studentId) {
  return request({
    url: `/api/homework/${homeworkId}/student/${studentId}/answers`,
    method: 'get'
  })
}

// 教师批改作业
export function gradeAnswer(answerId, teacherComment, score) {
  return request({
    url: `/api/homework/answer/${answerId}/grade`,
    method: 'put',
    params: { teacherComment, score }
  })
}

// 自动批改单个答案
export function autoGradeAnswer(answerId) {
  return request({
    url: `/api/homework/answer/${answerId}/auto-grade`,
    method: 'put'
  })
}

// 自动批改整份作业
export function autoGradeHomework(homeworkId, studentId) {
  return request({
    url: `/api/homework/${homeworkId}/student/${studentId}/auto-grade`,
    method: 'put'
  })
}

// AI出题相关
export function generateQuestionsByAI(categoryId, knowledgePointId, questionType, questionCount = 1, topic = '') {
  return request({
    url: '/api/homework/ai/generate',
    method: 'post',
    params: {
      categoryId,
      knowledgePointId,
      questionType,
      questionCount,
      topic
    }
  })
}

export function generateQuestionContent(topic, questionType) {
  return request({
    url: '/api/homework/ai/question',
    method: 'post',
    params: {
      topic,
      questionType
    }
  })
}

export function generateStandardAnswer(questionContent, questionType) {
  return request({
    url: '/api/homework/ai/answer',
    method: 'post',
    params: {
      questionContent,
      questionType
    }
  })
}

export function generateOptions(questionContent, standardAnswer) {
  return request({
    url: '/api/homework/ai/options',
    method: 'post',
    params: {
      questionContent,
      standardAnswer
    }
  })
}

// 创建错题记录
export function createMistakeRecord(data) {
  return request({
    url: '/api/mistake-book',
    method: 'post',
    data
  })
}

// 设置作业的知识点
export function setHomeworkKnowledgePoints(homeworkId, knowledgeIds) {
  return request({
    url: `/api/knowledge-points/homework/${homeworkId}`,
    method: 'post',
    data: knowledgeIds
  })
}

// 获取作业的知识点
export function getHomeworkKnowledgePoints(homeworkId) {
  return request({
    url: `/api/knowledge-points/homework/${homeworkId}`,
    method: 'get'
  })
}

// 获取分类下的知识点
export function getKnowledgePointsByCategory(categoryId) {
  return request({
    url: `/api/knowledge-points/category/${categoryId}`,
    method: 'get'
  })
}

// 获取所有知识点
export function getAllKnowledgePoints() {
  return request({
    url: '/api/knowledge-points',
    method: 'get'
  })
}

// 获取题目的知识点信息
export function getQuestionKnowledgePoint(questionId) {
  return request({
    url: `/api/homework/question/${questionId}/knowledge-point`,
    method: 'get'
  })
}